package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration //配置类
@Slf4j
public class OssConfigration {
    @Bean
    @ConditionalOnMissingBean
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
        log.info("开始创建阿里云文件上传对象:{}",aliOssProperties);
        return new AliOssUtil(aliOssProperties.getEndpoint(),aliOssProperties.getAccessKeyId(),aliOssProperties.getAccessKeySecret(),aliOssProperties.getBucketName());

    }

}
/*

1.在properties.yml中配置好各项参数的值
2.准备一个实体类封装各项参数
3.准备一个Configrationproperties的类将yml的参数值映射到类的参数上
4.配置一个新的配置类，用于创建AliOssUtil的对象，并交给ioc容器
5.后期需要文件上传时用autowired依赖注入


*/
